using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;
using AntEater.ComponentModel.BuildElements;
using AntEater.ComponentModel;

namespace AntEater.Runtime.Services.Transformation
{

    /// <summary>
    /// Provides a set of transformer helper methods.
    /// </summary>
    internal static class BuildElementPropertyTransformationHelper
    {

        /// <summary>
        /// Converts a List of Targets into an XML attribute String.
        /// </summary>
        /// <param name="targetList">The target list.</param>
        /// <returns></returns>
        public static string ListOfTargetsToXml(TargetCollection targetList) {
            string result = null;

            if (targetList != null) {
                result = string.Join(";", targetList.ToArray());
            }

            return result;
        }

        /// <summary>
        /// Converts an XML Attribute String into a List of Targets.
        /// </summary>
        /// <param name="targetList">The target list.</param>
        /// <param name="buildFileDefinition">The build file definition.</param>
        /// <returns></returns>
        public static TargetCollection ListOfTargetsFromXml(string targetList, BuildFileDefinition buildFileDefinition) {
            TargetCollection result = null;

            if (!string.IsNullOrEmpty(targetList)) {
                result = new TargetCollection(buildFileDefinition, targetList.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries));
            }

            return result;
        }

    }
}
